package design_pattern;

public class Singleton_Pattern {
    private volatile static Singleton_Pattern singleton;

    private Singleton_Pattern(){}

    public static Singleton_Pattern getInstance(){
        if(singleton==null){
            //因为this是对象锁，静态的话只能用类锁
            synchronized (Singleton_Pattern.class){
                if (singleton==null){
                    singleton = new Singleton_Pattern();
                }
            }
        }
        return singleton;
    }

    public static void main(String[] args) {
        Singleton_Pattern s = Singleton_Pattern.getInstance();
        System.out.println(s);
    }
}
